package model

import (
	"express/global"
	"express/handler/respone"
)

type Users struct {
	Id             int             `gorm:"primary_key" json:"id"`
	Phone          string          `label:"手机号"  gorm:"type:varchar(11);not null;default:''" json:"phone"`
	ExpressNumbers []ExpressNumber `gorm:"ForeignKey:user_id" json:"express_numbers"`
}

func (Users) TableName() string {
	return "users"
}

//查询所有用户
//func (f *Users) Detail() (users []Users) {
//	db := dao.InitDB()
//	conn := db.GetDb()
//
//	conn.Find(&user) //select * from user
//	return
//
//	//users := []Users{}
//	//db.Find(&users)
//	//fmt.Println(&users) //获取所有数据
//}

func (u *Users) GetAllUsers(userId string) (users []respone.Users) {
	//加入了预加载
	global.DB.Model(&Users{}).Preload("ExpressNumbers").Preload("ExpressNumbers.NumNums").Find(&users)
	return
}

//func GetAllUsers(b *[]Users) (err error) {
//	if err = global.DB.Find(b).Error; err != nil {
//		return err
//	}
//	return nil
//}
